/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sfs2x.extension.fourinarow.main;

import com.athena.objects.Game;
import com.athena.objects.Player;
import com.smartfoxserver.v2.core.ISFSEvent;
import com.smartfoxserver.v2.core.SFSEventParam;
import com.smartfoxserver.v2.entities.Room;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.exceptions.SFSException;
import com.smartfoxserver.v2.extensions.BaseServerEventHandler;

/**
 *
 * @author dodinhchien
 */
public class LeaveRoomEventHandle extends BaseServerEventHandler {

    @Override
    public void handleServerEvent(ISFSEvent event) throws SFSException {
        Room room = (Room) event.getParameter(SFSEventParam.ROOM);
        User user = (User) event.getParameter(SFSEventParam.USER);
        if (room != null) {
            FourinarowExtension extension = (FourinarowExtension) getParentExtension();
            Game curGame = extension.getGamesList().get(room.getId());
            if (curGame != null) {
                Player player = curGame.getPlayers().get(user.getId());
                if (player != null) {
                    if (!curGame.isStarted()) {
                        player.setRoomId(-1);
                        curGame.getPlayers().remove(user.getId());
                        if (curGame.getPlayers().size() > 0) {

                        } else {

                        }
                    }

                }
            }
        }
    }

}
